package com.cy.pj.goods.service;

import com.cy.pj.goods.dao.GoodsDao;
import com.cy.pj.goods.pojo.Goods;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService{
    private static final Logger logger = LoggerFactory.getLogger(GoodsServiceImpl.class);
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public int deleteById(Integer id) {
        return goodsDao.deleteById(id);
    }

    @Override
    public List<Goods> findGoods() {
        long start = System.currentTimeMillis();
        List<Goods> list = goodsDao.findGoods();
        long end = System.currentTimeMillis();
        logger.info("findGoods time -> {}",(end-start));
        return list;
    }

    @Override
    public int saveGoods(Goods entity) {
        int rows = goodsDao.insertGoods(entity);
        return rows;
    }

    @Override
    public Goods fingById(Integer id) {
        return goodsDao.findById(id);
    }

    @Override
    public int updateGoods(Goods goods) {
        return goodsDao.updateGoods(goods);
    }
}
